// This javascript document contains important method calls and custom scripts for Locality Theme.
jQuery(document).ready(function(){
	
	$ = jQuery;	
	
/*-----------------------------------------------------------------------------------*/
/*	Selec box options in advance search
/*-----------------------------------------------------------------------------------*/	
	$('.search-select').not('.ie7 .search-select').selectbox();
	
	
/*-----------------------------------------------------------------------------------*/
/*	this function attaches focus and blur events with input elements
/*-----------------------------------------------------------------------------------*/	
	var addFocusAndBlur = function($input, $val){
		
		$input.focus(function(){
			if (this.value == $val) {this.value = '';}
		});
		
		$input.blur(function(){
			if (this.value == '') {this.value = $val;}
		});
	}
	addFocusAndBlur(jQuery('#s'),'Search....');
	addFocusAndBlur(jQuery('#subs-bar'),'E-mail address');
	addFocusAndBlur(jQuery('#min-price'),'min...');
	addFocusAndBlur(jQuery('#max-price'),'max...');


/*-----------------------------------------------------------------------------------*/
/*	fade effect for images
/*-----------------------------------------------------------------------------------*/	
	$("img").not('.ie8 .logo-footer,.ie7 .logo-footer,.bar-icons img')
			.hover(function() {
							  $(this).stop(true,true).animate({opacity: "0.6"}, 'slow');
							},
							function() {
							  $(this).stop(true,true).animate({opacity: "1"}, 'slow');
							});
	

/*-----------------------------------------------------------------------------------*/
/*	Equal Heights
/*-----------------------------------------------------------------------------------*/	
	$(".table-cols li").equalHeights();
		

/*-----------------------------------------------------------------------------------*/
/*	Cross Browser CSS Fixes
/*-----------------------------------------------------------------------------------*/	
	$("#pagination a:first-child").css('marginLeft',0);
	$(".side-widget ul li:first-child").css('borderTop',0).css('paddingTop',0);
	$(".side-widget ul li:last-child").css('borderBottom',0);
	$(".footer-widget ul li:first-child").css('borderTop',0).css('marginLeft',0).css('paddingTop',0);
	$(".footer-widget ul li:last-child").css('borderBottom',0);
	$(".post-meta > span:last-child").css('marginRight',0);
	$(".footer-nav li:first-child a").css('paddingLeft',0);
	$(".main-nav > li:last-child").css('background','none');
	

/*-----------------------------------------------------------------------------------*/
/*	Cycle Plugins Calls for Property Single Page Gallery and Home Page Slider
/*-----------------------------------------------------------------------------------*/	
	if(jQuery().cycle)
	{
		$('#slideshow').cycle({ 
		    fx:     'scrollHorz', 
		    speed:  'fast', 
		    timeout: 4000, 
		    pager:  '#nav',      
			pagerAnchorBuilder: function(idx, slide) { 
				return '<li><a href="#"><img src="' + slide.src + '" width="85" height="60" /></a></li>'; 
			}
	  	});
		
		
		// slider at home
		$('.slides').cycle({
			fx: 'scrollHorz',
			pause: 'true',
			speed: '1000',
			manualTrump: false,
			prev: '.prev',
			next: '.next'	
		});
		
		// side testimonials slider
		$('#testimonials-slider').cycle({
			fx: 'scrollHorz',
			pause: 'true',
			speed: '1000' 		
		});
		
	}

	
/*-----------------------------------------------------------------------------------*/
/*	fade effect for images
/*-----------------------------------------------------------------------------------*/	
	$('.accordian li p').slideUp(100);
	$('.accordian li.active p').slideDown(100);
	$('.accordian li h5').click(function(){
		if(!$(this).parent('li').hasClass('active')){
			$('.accordian li.active p').slideUp(500);
			$('.accordian li.active').removeClass('active');
			$(this).siblings('p').slideDown(500);
			$(this).parent('li').addClass('active');	
		}
	});
	
	
/*-----------------------------------------------------------------------------------*/
/*	Contact Form Validate and AJAX Function
/*-----------------------------------------------------------------------------------*/	
	if( jQuery().validate ) 
	{		
			
		var contact_options = { 
				target: '#message-sent',
				beforeSubmit: function(){
										$('#contact-loader').fadeIn('fast');
										$('#message-sent').fadeOut('fast');
								}, 
				success: function(){
									$('#contact-loader').fadeOut('fast');
									$('#message-sent').fadeIn('fast');
									$('#contact-form').resetForm();
								}
		}; 
		
		$('#contact-form').validate({
			submitHandler: function(form) {
				$(form).ajaxSubmit(contact_options);
		   }
		});
							
	}	

/*-----------------------------------------------------------------------------------*/
/*	Main Navigation Dropdown Slidedown Effect
/*-----------------------------------------------------------------------------------*/		
	$('.main-nav li').hover(function(){
		  	$(this).children('ul').stop(true,true).slideDown(400);
	}, function(){
			$(this).children('ul').stop(true,true).fadeOut(300);
	});

	

	
/*-----------------------------------------------------------------------------------*/
/*	Pretty Photo 
/*-----------------------------------------------------------------------------------*/	

$(".pretty-photo").prettyPhoto({
				deeplinking: false,
				social_tools: false
			});
});